//
//  GeneralHelper.m
//
//  Created by ZhàoYǒng on 23/10/2017.
//  Copyright © 2017 ZhàoYǒng. All rights reserved.
//

#import "GeneralHelper.h"
#import <UserNotifications/UserNotifications.h>
#import <AVFoundation/AVFoundation.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
#import "StringHelper.h"

@implementation GeneralHelper

// GCD

void AfterDispatch(double delayInSeconds, dispatch_block_t _Nullable block) {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)), dispatch_get_main_queue(), block);
}

void MainDispatch(dispatch_block_t _Nullable block) {
    dispatch_async(dispatch_get_main_queue(), block);
}

void GlobalDispatch(dispatch_block_t _Nullable block) {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
}

// Keychain

NSString * _Nonnull KeychainService() {
    return @"ZY_KeychainKey";
}

NSMutableDictionary *GetKeychainQuery(NSString *service) {
    return [NSMutableDictionary dictionaryWithObjectsAndKeys:
            (__bridge id)kSecClassGenericPassword,(__bridge id)kSecClass,
            service, (__bridge id)kSecAttrService,
            service, (__bridge id)kSecAttrAccount,
            (__bridge id)kSecAttrAccessibleAfterFirstUnlock,(__bridge id)kSecAttrAccessible,
            nil];
}

void KeychainSave(NSString *service, id data) {
    //Get search dictionary
    NSMutableDictionary *keychainQuery = GetKeychainQuery(service);
    //Delete old item before add new item
    SecItemDelete((__bridge CFDictionaryRef)keychainQuery);
    //Add new object to search dictionary(Attention:the data format)
    [keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(__bridge id)kSecValueData];
    //Add item to keychain with the search dictionary
    SecItemAdd((__bridge CFDictionaryRef)keychainQuery, NULL);
}

id KeychainLoad(NSString *service) {
    id ret = nil;
    NSMutableDictionary *keychainQuery = GetKeychainQuery(service);
    //Configure the search setting
    //Since in our simple case we are expecting only a single attribute to be returned (the password) we can set the attribute kSecReturnData to kCFBooleanTrue
    [keychainQuery setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
    [keychainQuery setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
    CFDataRef keyData = NULL;
    if (SecItemCopyMatching((__bridge CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {
        @try {
            ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData];
        } @catch (NSException *e) {
            NSLog(@"Unarchive of %@ failed: %@", service, e);
        } @finally {
        }
    }
    if (keyData)
        CFRelease(keyData);
    return ret;
}

void KeychainDelete(NSString *service) {
    NSMutableDictionary *keychainQuery = GetKeychainQuery(service);
    SecItemDelete((__bridge CFDictionaryRef)keychainQuery);
}

NSString * _Nullable KeychainUDID() {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *udid = [defaults stringForKey:@"LocalUniqueDeviceIdentifier"];
    if (!StringIsValid(udid)) {
        udid = KeychainLoad(KeychainService());
        if (!StringIsValid(udid)) {
            udid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
            udid = StringGetMD5(udid);
            KeychainSave(KeychainService(), udid);
        }
        [defaults setObject:udid forKey:@"LocalUniqueDeviceIdentifier"];
        [defaults synchronize];
    }
    return udid;
}

// Language

NSString *_curLan = nil;

NSString * _Nullable CurrentLanguage() {
    if (StringIsValid(_curLan)) {
        return _curLan;
    }
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLang = languages.firstObject;
    if (!StringIsValid(currentLang)) {
        _curLan = @"en";
    }else {
        NSArray *_s = [currentLang componentsSeparatedByString:@"-"];
        _curLan = _s.firstObject;
    }
    return _curLan;
    //zh-Hans   简体中文
    //zh-Hant   繁体中文
    //zh-HK     繁体中文香港
    //en        英语
    //ja        日语
    //ko        韩语
    //fr        法语
    
    /*
     AppleLanguages =     @[@"zh-Hans",
     @"en",
     @"fr",
     @"de",
     @"ja",
     @"nl",
     @"it",
     @"es",
     @"pt",
     @"pt-PT",
     @"da",
     @"fi",
     @"nb",
     @"sv",
     @"ko",
     @"zh-Hant",
     @"ru",
     @"pl",
     @"tr",
     @"uk",
     @"ar",
     @"hr",
     @"cs",
     @"el",
     @"he",
     @"ro",
     @"sk",
     @"th",
     @"id",
     @"en-GB",
     @"ca",
     @"hu",
     @"vi"];
     */
}

NSString * _Nullable CurInputMode() {
    NSString *mode = nil;
    NSArray *modes = [UITextInputMode activeInputModes];
    if (modes.count > 0) {
        mode = [modes[0] primaryLanguage];
    }
    return mode;
}

NSString * _Nullable CurrentLanguageString() {
    NSString *languageString = @"英语";
    if ([@"zh" isEqualToString:CurrentLanguage()]) {
        languageString = @"简体中文";
    }else if ([@"en" isEqualToString:CurrentLanguage()]) {
        languageString = @"英语";
    }else if ([@"fr" isEqualToString:CurrentLanguage()]) {
        languageString = @"法语";
    }else if ([@"ja" isEqualToString:CurrentLanguage()]) {
        languageString = @"日语";
    }else if ([@"ko" isEqualToString:CurrentLanguage()]) {
        languageString = @"韩语";
    }
    return languageString;
}


// 系统
// 获取磁盘总容量
unsigned long long TotalDiskSize() {
    struct statfs buf;
    unsigned long long freeSpace = -1;
    if (statfs("/var", &buf) >= 0)
    {
        freeSpace = (unsigned long long)(buf.f_bsize * buf.f_blocks);
    }
    return freeSpace;
}
// 获取磁盘剩余容量
unsigned long long AvailableDiskSize() {
    struct statfs buf;
    unsigned long long freeSpace = -1;
    if (statfs("/var", &buf) >= 0)
    {
        freeSpace = (unsigned long long)(buf.f_bsize * buf.f_bavail);
    }
    return freeSpace;
}
// 容量转换
NSString * _Nullable FileSizeToString(unsigned long long fileSize) {
    NSInteger KB = 1024;
    NSInteger MB = KB*KB;
    NSInteger GB = MB*KB;
    
    if (fileSize < 10) {
        return @"0 B";
        
    }else if (fileSize < KB) {
        return @"< 1 KB";
        
    }else if (fileSize < MB)  {
        return [NSString stringWithFormat:@"%.1f KB",((CGFloat)fileSize)/KB];
        
    }else if (fileSize < GB)  {
        return [NSString stringWithFormat:@"%.1f MB",((CGFloat)fileSize)/MB];
        
    }else {
        return [NSString stringWithFormat:@"%.1f GB",((CGFloat)fileSize)/GB];
    }
}
// 获取本机名称
NSString * _Nullable DeviceName() {
    NSString *phoneName = [[UIDevice currentDevice] name];
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@／：；（）￥「」“”＂、”[]{}#%-*+=_\\|~＜＞$€^·'@#$%^&*()”_+'\""];
    phoneName = [phoneName stringByTrimmingCharactersInSet:set];
    phoneName = [phoneName stringByReplacingOccurrencesOfString:@"“" withString:@""];
    phoneName = [phoneName stringByReplacingOccurrencesOfString:@"”" withString:@""];
    phoneName = [phoneName stringByReplacingOccurrencesOfString:@"“" withString:@""];
    phoneName = [phoneName stringByReplacingOccurrencesOfString:@"iPhone" withString:@""];
    phoneName = [phoneName stringByReplacingOccurrencesOfString:@"的" withString:@""];
    phoneName = [phoneName stringByReplacingOccurrencesOfString:@"de" withString:@""];
    
    phoneName = [NSString stringWithFormat:@"%@%@的导入", phoneName, DevicePlatform()];
    
    if ([phoneName isEqualToString:@""]) {
        phoneName = DevicePlatform();
    }
    
    return phoneName;
}
// 获取本机型号
NSString * _Nullable DevicePlatform() {
    int mib[2];
    size_t len;
    char *machine;
    
    mib[0] = CTL_HW;
    mib[1] = HW_MACHINE;
    sysctl(mib, 2, NULL, &len, NULL, 0);
    machine = malloc(len);
    sysctl(mib, 2, machine, &len, NULL, 0);
    
    NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
    free(machine);
    
    if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G";// (A1203)";
    if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";// (A1241/A1324)";
    if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";// (A1303/A1325)";
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";// (A1332)";
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";// (A1332)";
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4";// (A1349)";
    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";// (A1387/A1431)";
    if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";// (A1428)";
    if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";// (A1429/A1442)";
    if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c";// (A1456/A1532)";
    if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c";// (A1507/A1516/A1526/A1529)";
    if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s";// (A1453/A1533)";
    if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s";// (A1457/A1518/A1528/A1530)";
    if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";// (A1522/A1524)";
    if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";// (A1549/A1586)";
    if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s Plus";// (A1522/A1524)";
    if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s";// (A1549/A1586)";
    if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7 Plus";// (A1522/A1524)";
    if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7";// (A1549/A1586)";
    
    if ([platform isEqualToString:@"iPod1,1"])   return @"iPod Touch 1";// (A1213)";
    if ([platform isEqualToString:@"iPod2,1"])   return @"iPod Touch 2";// (A1288)";
    if ([platform isEqualToString:@"iPod3,1"])   return @"iPod Touch 3";// (A1318)";
    if ([platform isEqualToString:@"iPod4,1"])   return @"iPod Touch 4";// (A1367)";
    if ([platform isEqualToString:@"iPod5,1"])   return @"iPod Touch 5";// (A1421/A1509)";
    
    if ([platform isEqualToString:@"iPad1,1"])   return @"iPad 1";// (A1219/A1337)";
    
    if ([platform isEqualToString:@"iPad2,1"])   return @"iPad 2";// (A1395)";
    if ([platform isEqualToString:@"iPad2,2"])   return @"iPad 2";// (A1396)";
    if ([platform isEqualToString:@"iPad2,3"])   return @"iPad 2";// (A1397)";
    if ([platform isEqualToString:@"iPad2,4"])   return @"iPad 2";// (A1395+New Chip)";
    if ([platform isEqualToString:@"iPad2,5"])   return @"iPad Mini 1";// (A1432)";
    if ([platform isEqualToString:@"iPad2,6"])   return @"iPad Mini 1";// (A1454)";
    if ([platform isEqualToString:@"iPad2,7"])   return @"iPad Mini 1";// (A1455)";
    
    if ([platform isEqualToString:@"iPad3,1"])   return @"iPad 3";// (A1416)";
    if ([platform isEqualToString:@"iPad3,2"])   return @"iPad 3";// (A1403)";
    if ([platform isEqualToString:@"iPad3,3"])   return @"iPad 3";// (A1430)";
    if ([platform isEqualToString:@"iPad3,4"])   return @"iPad 4";// (A1458)";
    if ([platform isEqualToString:@"iPad3,5"])   return @"iPad 4";// (A1459)";
    if ([platform isEqualToString:@"iPad3,6"])   return @"iPad 4";// (A1460)";
    
    if ([platform isEqualToString:@"iPad4,1"])   return @"iPad Air";// (A1474)";
    if ([platform isEqualToString:@"iPad4,2"])   return @"iPad Air";// (A1475)";
    if ([platform isEqualToString:@"iPad4,3"])   return @"iPad Air";// (A1476)";
    if ([platform isEqualToString:@"iPad4,4"])   return @"iPad Mini 2";// (A1489)";
    if ([platform isEqualToString:@"iPad4,5"])   return @"iPad Mini 2";// (A1490)";
    if ([platform isEqualToString:@"iPad4,6"])   return @"iPad Mini 2";// (A1491)";
    
    if ([platform isEqualToString:@"i386"])      return @"iPhone Simulator";
    if ([platform isEqualToString:@"x86_64"])    return @"iPhone Simulator";
    return platform;
}

// 应用

NSString * _Nullable ApplicationName() {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleDisplayName"];
}
// 获取应用版本号
NSString * _Nullable ApplicationVersion() {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleShortVersionString"];
}
// 获取应用构建号
NSString * _Nullable ApplicationBuild() {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleVersion"];
}

NSString * _Nullable ApplicationBundleId() {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    return [infoDictionary objectForKey:@"CFBundleIdentifier"];
}

//用户是否允许推送
void IsAllowedNotification(void(^ _Nullable completionBlock)(BOOL isAllowed)) {

    if (@available(iOS 10.0, *)) {
        [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {
            if (completionBlock) {
                completionBlock(settings.authorizationStatus == UNAuthorizationStatusAuthorized);
            }
        }];
    } else if (@available(iOS 8.0, *)) {
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (completionBlock) {
            completionBlock(UIUserNotificationTypeNone != setting.types);
        }
    } else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if (completionBlock) {
            completionBlock(type != UIRemoteNotificationTypeNone);
        }
#pragma clang diagnostic pop
    }
    
}

//正则去除HTML网络标签
NSString * _Nullable HtmlTrimming(NSString * _Nullable htmlString) {
    NSRegularExpression *regularExpretion = [NSRegularExpression regularExpressionWithPattern:@"<[^>]*>|\n|&nbsp" options:0 error:nil];
    NSString *newstring = [regularExpretion stringByReplacingMatchesInString:htmlString options:NSMatchingReportProgress range:NSMakeRange(0, htmlString.length) withTemplate:@""];
    return newstring;
}

//正则获取HTML <img> 网络标签
NSArray * _Nullable HtmlScreenOutImage(NSString * _Nullable htmlString) {
    if (htmlString == nil) return nil;
    
    NSMutableArray * imageUrlArray = [NSMutableArray arrayWithCapacity:1];
    //标签匹配
    NSString *parten = @"<img(.*?)>";
    NSError* error = NULL;
    NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:parten options:0 error:&error];
    NSArray *match = [reg matchesInString:htmlString options:0 range:NSMakeRange(0, htmlString.length)];
    //NSArray *match = [reg matchesInString:htmlString options:0 range:NSMakeRange(0, htmlString.length - 1)];

    for (NSTextCheckingResult *result in match) {
        //过去数组中的标签
        NSRange range = result.range;
        NSString *subString = [htmlString substringWithRange:range];
        //从图片中的标签中提取ImageURL
        NSRegularExpression *subReg = [NSRegularExpression regularExpressionWithPattern:@"http://(.*?)\"" options:0 error:nil];
        NSArray *match = [subReg matchesInString:subString options:0 range:NSMakeRange(0, subString.length)];
        //NSArray *match = [reg matchesInString:htmlString options:0 range:NSMakeRange(0, htmlString.length - 1)];
        NSTextCheckingResult *subRes = match[0];
        NSRange subRange = subRes.range;
        //subRange.length = subRange.length -1;
        NSString * imageUrl = [subString substringWithRange:subRange];
        
        //将提取出的图片URL添加到图片数组中
        [imageUrlArray addObject:imageUrl];
    }
    
    return imageUrlArray.count > 0 ? imageUrlArray : nil;
}

// mov格式转mp4格式
void TransformMOVToMP4(NSURL * _Nullable movUrl,
                       TansformVedioCompleted _Nullable completionBlock,
                       TansformVedioFail _Nullable failureBlock) {

    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:movUrl options:nil];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
    NSLog(@"%@",compatiblePresets);
    
    if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {
        
        NSDate *date = [NSDate date];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyyMMddHHmmss"];
        NSString *uniqueName = [NSString stringWithFormat:@"%@.mp4",[formatter stringFromDate:date]];
        NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, 0)[0];
        NSString * resultPath = [docPath stringByAppendingPathComponent:uniqueName];
        NSLog(@"Output File Path : %@",resultPath);
        
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
        exportSession.outputURL = [NSURL fileURLWithPath:resultPath];
        exportSession.outputFileType = AVFileTypeMPEG4;//可以配置多种输出文件格式
        exportSession.shouldOptimizeForNetworkUse = YES;
        [exportSession exportAsynchronouslyWithCompletionHandler:^ {
             switch (exportSession.status) {
                 case AVAssetExportSessionStatusUnknown:
                 case AVAssetExportSessionStatusWaiting:
                 case AVAssetExportSessionStatusExporting:
                 case AVAssetExportSessionStatusFailed:
                 case AVAssetExportSessionStatusCancelled:
                     if (failureBlock) failureBlock();
                     break;
                 case AVAssetExportSessionStatusCompleted: {
                     if (completionBlock) completionBlock(resultPath);
                     NSLog(@"Mp4 file size:%lf MB",[NSData dataWithContentsOfURL:exportSession.outputURL].length/1024.f/1024.f);
                     break;
                 }
                 default: break;
             }
         }];
    }
}

#pragma mark 音乐

void PlayEffectSound(NSString * _Nullable sound, NSString * _Nullable type) {
    if ([[AVAudioSession sharedInstance] isOtherAudioPlaying]) return;

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:sound ofType:type];    //创建音乐文件路径
    if (!StringIsValid(soundFilePath)) return;
    
    CFURLRef soundURL = (__bridge CFURLRef) [NSURL fileURLWithPath:soundFilePath];
    SystemSoundID sameViewSoundID;
    AudioServicesCreateSystemSoundID(soundURL, &sameViewSoundID);
    //变量SoundID与URL对应
    AudioServicesPlaySystemSound(sameViewSoundID);  //播放SoundID声音
}


FileType GetFileType(NSString * _Nullable pathEx) {
    FileType fileType = FileTypeUnknown;
    
    NSArray *videoEx = @[@"3gp", @"avi",@"flv", @"mkv",@"mov", @"mp4",@"rmvb",@"vob", @"wmv",@"asf",@"dat",@"f4v",@"mod",@"mpe",@"mpeg",@"mpg",@"m4v",@"flv",@"fla",@"swf",@"vcd",@"svcd",@"dvd",@"ts",@"mts",@"tod",@"3GP", @"AVI",@"FLV", @"MKV",@"MOV", @"MP4",@"RMVB",@"VOB", @"WMV",@"ASF",@"DAT",@"F4V",@"MOD",@"MPE",@"MPEG",@"MPG",@"M4V",@"FLV",@"FLA",@"SWF",@"VCD",@"SVCD",@"DVD",@"TS",@"MTS",@"TOD"];
    NSArray *photoEx = @[@"bmp", @"ico", @"jpg", @"pcx", @"png", @"tga", @"tif",@"tiff", @"jpeg", @"webp", @"gif",@"BMP", @"ICO", @"JPG", @"PCX", @"PNG", @"TGA", @"TIFF",@"TIF", @"JPEG", @"WEBP", @"GIF"];
    
    NSArray *audioEx = @[@"aac", @"amr",@"ape", @"flac",@"m4a", @"m4r",@"mmf", @"mp2",@"mp3", @"ogg",@"wav",@"wma",@"wv",@"acc",@"ace",@"aiff",@"ape",@"wave",@"mid",@"midi",@"xmf",@"AAC", @"AMR",@"APE", @"FLAC",@"M4A", @"M4R",@"MMF", @"MP2",@"MP3", @"OGG",@"WAV",@"WMA",@"WV",@"ACC",@"ACE",@"AIFF",@"APE",@"WAVE",@"MID",@"MIDI",@"XMF"];
    
    NSArray *zipEx = @[@"zip", @"rar",@"tar", @"gzip",@"uue", @"7-zip",@"jar", @"iso",@"dmg",@"7z",@"cab",@"compressed",@"uue",@"bz2",@"xz",@"z",@"arj",@"ZIP", @"RAR",@"TAR", @"GZIP",@"UUE", @"7-ZIP",@"JAR", @"ISO",@"DMG",@"7Z",@"CAB",@"COMPRESSED",@"UUE",@"BZ2",@"XZ",@"Z",@"ARJ"];
    
    NSArray *textEx = @[@"txt",@"webm",@"h",@"m",@"c",@"cpp",@"hpp",@"rb",@"go",@"TXT",@"WEBM",@"H",@"M",@"C",@"CPP",@"HPP",@"RB",@"GO"];
    
    if ([videoEx containsObject:[pathEx lowercaseString]]) {
        fileType = FileTypeVideo;
    }else if([photoEx containsObject:[pathEx lowercaseString]]) {
        fileType = FileTypePhoto;
    }else if([audioEx containsObject:[pathEx lowercaseString]]) {
        fileType = FileTypeAudio;
    }else if([@"docx" isEqualToString:[pathEx lowercaseString]] || [@"doc" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypeWord;
    }else if([@"xlsx" isEqualToString:[pathEx lowercaseString]] || [@"xls" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypeXls;
    }else if([@"xml" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypeXml;
    }else if([@"exe" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypeExe;
    }else if([@"pdf" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypePdf;
    }else if([@"html" isEqualToString:[pathEx lowercaseString]] || [@"htm" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypeHtml;
    }else if([zipEx containsObject:[pathEx lowercaseString]]) {
        fileType = FileTypeZip;
    }else if([@"rtf" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypeRTF;
    }else if([textEx containsObject:[pathEx lowercaseString]]) {
        fileType = FileTypeTxt;
    }else if([@"ppt" isEqualToString:[pathEx lowercaseString]] || [@"pptx" isEqualToString:[pathEx lowercaseString]]) {
        fileType = FileTypePPT;
    }
    
    return fileType;
}

@end
